﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
    
namespace MLY.Bll
{
    public static class Demo
    {
        public static string[] DemoStages = { "none", "DataTransfer", "Reports", "Inventory", "Alerts", "GotoHebrew", "Hebrew", "Done" };

        public static void MoveToNextDemoStage()
        {
            HttpContext.Current.Session["DemoStage"] = NextDemoStage((string)HttpContext.Current.Session["DemoStage"]);
            HttpContext.Current.Session["DemoSubStage"] = "1";
        }

        public static void Login(string UserId)
        {
            if (UserId == "39")
            {
                HttpContext.Current.Session["DemoStage"] = DemoStages[1];
                HttpContext.Current.Session["DemoSubStage"] = "1";
                //MLY.Utils.mlySendMail("Demo: user yoav2 has logged in", "yoav@mly.co.il", "", "pastch@gmail.com",
                //    "Hello!<br /> This mail was automatically created by MLY system. <br /> " +
                //    "This is to inform you that the user yoav2 has logged in from IP address: " + GetIP(), false, null);
                
            }
            else if (UserId == "44")
            {
                HttpContext.Current.Session["DemoStage"] = "Hebrew";
                HttpContext.Current.Session["DemoSubStage"] = "1";
                //MLY.Utils.mlySendMail("Demo: user yoav3 has logged in", "yoav@mly.co.il", "", "pastch@gmail.com",
                //    "Hello!<br /> This mail was automatically created by MLY system. <br /> " +
                //    "This is to inform you that the user yoav3 has logged in from IP address: " + GetIP(), false, null);
                

            }

        }

        public static void MoveToNextDemoSubStage()
        {            
            try
            {
                int CurSubStage = int.Parse((string)HttpContext.Current.Session["DemoSubStage"]);
                CurSubStage++;
                HttpContext.Current.Session["DemoSubStage"] = (CurSubStage.ToString());
            }
            catch { }
        }
        
        private static string NextDemoStage(string CurrentCode)
        {
              
            // returns the next stage of the demo
            bool found = false;
            int i = 0;
            string NextCode = "Done";

            while ((!found) && (i < (DemoStages.Length - 1)))
            {
                if (CurrentCode == DemoStages[i])
                {
                    found = true;
                    NextCode = DemoStages[i + 1];
                }
                i++;
            }
            return NextCode;
        }

        public static string Text(string Stage, string Substage, string Control)
        {
            string ReturnValue = "";

            switch (Stage)
            {
                case "DataTransfer":
                    switch (Substage)
                    {
                        case "1":
                            if (Control == "DemoLabel")
                                ReturnValue = "  Dear user<br /><br /> " + 
                                              "This system is a MLY Demo system, using this demo and follow the instructions in it you could get the feeling of how it can be if your Business had the MLY system. " + 
                                              "The instructions in this demo lead you in a way which will expose you to the benefits of using the MLY system, you will be able to see and understand all of the system main features and processes, and the way you will use them to help your business. Using this demo you can visit in all of the areas of the system and examine them and the thing you can do with MLY. " + 
                                              "This demo is in English but MLY system is relevant in all languages. " + 
                                              "<br /><br /> Yoav Feuerstein, MLY<br />Please go to Data Transfer";
                            break;
                        case "2":
                            if (Control == "DemoLabel")
                                ReturnValue = "You are at Data transfer Page. <br /> In this section you can uplaod your own data from your own computer and see how thr SC Cover system deal with it. ";
                            break;
                        case "3":
                            if (Control == "DemoLabel")
                                ReturnValue = "<span style=\"color:red;\">You are at Data transfer Page. Explanations part 2</span>";
                            break;
                        case "4":
                            if (Control == "DemoLabel")
                                ReturnValue = "<span style=\"color:red;\">You are at Data transfer Page. Explanations part 3</span>";
                            break;
                        case "5":
                            if (Control == "DemoLabel")
                                ReturnValue = "<span style=\"color:red;\">You are at Data transfer Page. Explanations part 4</span>";
                            break;
                        default:
                            ReturnValue = "Data Transfer default. Substage: " + Substage;
                            break;
                    }
                    break;
                case "Reports":
                    switch (Substage)
                    {
                        case "1":
                            if (Control == "DemoLabel")
                                ReturnValue = "Please go to reports stage.<br /> In this section you can see all the reports that the SC Cover system can produce, more specific information abuat each reports is in under each report name.";
                            break;
                        case "2":
                            if (Control == "DemoLabel")
                                ReturnValue = "<span style=\"color:red;\">You are at reports Page. Explanations</span>";
                            break;
                        default:
                            ReturnValue = "Data Transfer default";
                            break;

                    }
                    break;
                case "Inventory":
                    switch (Substage)
                    { 
                        case "1":
                            if (Control == "DemoLabel")
                                ReturnValue = "Please go to inventory page";
                            break;
                        case "2":
                            if (Control == "DemoLabel")
                                ReturnValue = "Here you can see your inventory grid. There are a lot of options to sort or group the data, as long as edit it. <br /> " + 
                                              "for example - press a column header to sort the grid by this column. Or press the highlighted Export button to receive excel file with all the data. <br /> " + 
                                              "If a filter was applied - Excel will contain only the data after the filter was applied.";
                            break;
                        default:
                            ReturnValue = "Inventory default";
                            break;

                    }
                    break;
                case "Alerts":
                    switch (Substage)
                    {
                        case "1":
                            if (Control == "DemoLabel")
                                ReturnValue = "The next part of the demo will be shown on the Alerts page. Please follow the highlighted link";
                            break;
                        case "2":
                            if (Control == "DemoLabel")
                                ReturnValue = "This is the alerts definition page. To create a new alert, please press the \"Create alert\" link";
                            break;
                        case "3":
                            if (Control == "DemoLabel")
                                ReturnValue = "Here a new alert is created. You should define when do you want to be notified, and how.";
                            break;
                        case "4":
                            if (Control == "DemoLabel")
                                ReturnValue = "Now, when the alert was created, please go to see Inventory page to see what happens when somebody changes something and an alert actually works";
                            break;
                        case "5":
                            if (Control == "DemoLabel")
                                ReturnValue = "Here, at your inventory page - please see the highlighted row(s). This happened because somebody changed the data, and your alert highlighted the relevant row(s) for you. If you defined that you want to receive mails - the system would send an email to you about this alert too.";
                            break;
                        default:
                            ReturnValue = "Alerts default. Substage: " + Substage;
                            break;
                    }
                    break;
                case "GotoHebrew":
                    if (Control == "DemoLabel")
                        ReturnValue = "The system is multilanguage. To change the language to hebrew, you can press the Israeli flag at the Right Top of the screen. Another option is to login with the user yoav3 (password - yoav3) to see that he has hebrew as the default language. <br /> Please logout and login as yoav3.";
                    break;
                case "Hebrew":
                    if (Control == "DemoLabel")
                        ReturnValue = "As you can see - yoav3 user has the site in Hebrew by default. This demo is over now. Thank you!";
                    break;
                case "Done":
                    ReturnValue = "The demo is now over. Thank you!";
                    break;
                default:
                    ReturnValue = "<span style=\"color:Red;\">Undefined demo text: Stage: " + Stage + " Substage: " + Substage + " Control: " + Control + "</span>";
                    break;
            }

            return ReturnValue;
        }
        
        public static string GetIP()
        {
            try
            {
                HttpRequest currentRequest = HttpContext.Current.Request;
                string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];

                if (ipAddress == null || ipAddress.ToLower() == "unknown")
                    ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];

                return ipAddress;
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}
